/* hud.cpp
*
*/
#include "hud.h"

/* Constructor
*
*/
HUD::HUD(int w, int h) {
 __setBitmap(create_bitmap(w,h));
 clear_bitmap(_sprite);
 _background = 0x00;
 for(int i = 0; i < 8; ++i) {
    _elementArr[i] = 0x00;
    _idArr[i] = -1;
    _hideArr[i] = 0;
    _stretchXArr[i] = 0;
  }
}

/* Destructor
*
*/
HUD::~HUD() {
    int i;
    destroy_bitmap(_background);
    for( i = 0; i < 8; ++i )
      if ( _elementArr[i] ) destroy_bitmap(_elementArr[i]->__getSprite());
}

/* __update()
*
*/
void HUD::__update() {
 clear_bitmap(_sprite);
 if ( _background ) blit(_background, _sprite, 0, 0, 0, 0,
 _background->w, _background->h);

  for(int i = 0; i < 8; ++i) {
    if ( _elementArr[i] && _hideArr[i] == 0 ) {
      if ( _stretchXArr[i] == 0 ) {
        draw_sprite(_sprite, _elementArr[i]->__getSprite(),
        _elementArr[i]->__getX(), _elementArr[i]->__getY());
      }
      else {
        stretch_sprite(_sprite, _elementArr[i]->__getSprite(),
        _elementArr[i]->__getX(), _elementArr[i]->__getY(),
        _stretchXArr[i], _elementArr[i]->__getSprite()->h);      
      }
    }
  }
}
/* __setStretchX() : stretch an element
*
*/
void HUD::__setStretchX(int eId, int size) { _stretchXArr[eId] = size; }

/*  __deleteId() : destroy an element from the HUD
*   @args:
*     - int id : Id of the element to destroy
*     - int force_destroy : 1=destroy_bitmap enabled
*/
void HUD::__deleteId(int id, int force_destroy) {
 if ( _elementArr[id] ) {
    if ( force_destroy ) destroy_bitmap(_elementArr[id]->__getSprite());
    _elementArr[id] = 0x00;
    _idArr[id] = -1;
  }
}
